<template>
  <view @touchmove.stop.prevent="" class="mask" :class="maskState ? 'show' : 'none' " @click="toggleMask">
    <view class="mask-content" :style="{bottom : `${keyBoardHeight}px`}" :class="keyBoardHeight ? 'visible' : 'hidden'" @click.stop.prevent="">
      <view class="mask-content-topbar">
        <view class="left" @click="toggleMask">取消</view>
        <view class="right" @click="confirm">确定</view>
      </view>
      <view class="mask-content-input">
				<input
            class="textarea"
            v-model="content"
            :placeholder="placeholder"
            :focus="focus"
            :adjust-position="false"
            :hold-keyboard="true"
            @confirm="confirm"
            confirm-type="done"/>
        <text class="unit">{{unit}}</text>
      </view>
    </view>
  </view>
</template>

<script>
import {mapGetters} from 'vuex'
export default {
  name: "ygcComment",
  //属性
  props: {
    placeholder: {
      type: String,
      default: '',
    },
    unit:{
      type: String,
      default: ''
    }
  },
  data() {
    return {
      maskState: 0,
      content: '',
      focus: false,
    };
  },
  computed:{
    ...mapGetters(['keyBoardHeight', 'inputValue'])
  },
  watch:{
    keyBoardHeight(newValue){
      this.content = this.inputValue
      if(newValue === 0){
        this.toggleMask()
      }
    },
  },
  methods: {
    toggleMask(type){
      this.maskState = type === 'show'
      if(!this.maskState) this.content = ''
      this.focus = this.maskState ? true : false
    },
    confirm() {
      this.$emit('valueChange',this.content)
      this.toggleMask()
    }
  }
}
</script>

<style lang="scss" scoped>
.mask{
  display: flex;
  align-items: flex-end;
  position: fixed;
  left: 0;
  top: var(--window-top);
  bottom: 0;
  width: 100%;
  min-height: 200vh;
  background: rgba(0,0,0,0);
  z-index: 9995;
  .mask-content{
    position: fixed;
    width: 100%;
    background: #FFFFFF;
    // overflow-y:scroll;
    display: flex;
    flex-direction: column;
    .mask-content-topbar{
      display: flex;
      justify-content: space-between;
      padding: 30rpx 20rpx;
      font-size: 28rpx;
      .left{
        width: 300rpx;
        height: 60rpx;
        text-align: center;
        line-height: 60rpx;
        color: #2D8CF0;
        border: 2rpx solid #2D8CF0;
        border-radius: 5rpx;
      }
      .right{
        width: 300rpx;
        height: 60rpx;
        text-align: center;
        line-height: 60rpx;
        background-color: #2D8CF0;
        color: #ffffff;
        border: 2rpx solid #2D8CF0;
        border-radius: 5rpx;
      }
    }
    .mask-content-input{
      margin: 0rpx 20rpx 30rpx;
      border:2rpx solid #888888;
      display: flex;
      padding: 0 16rpx;
      border-radius: 10rpx;
      align-items: center;
      .textarea {
        flex: 1;
        height: 70rpx;
        font-size: 35rpx !important;
        color: black;
      }
      .unit{

      }
    }
    //#ifdef MP-WEIXIN
    &.visible{
      opacity: 1;
    }
    &.hidden{
      opacity: 0;
    }
    //#endif
  }
  &.none{
    display: none;
  }
  &.show{
    background: rgba(0,0,0,.4);
  }
}

</style>
